import { ExtractPropTypes } from 'vue'
import {
  FormLabelPositions,
  FormLabelPosition,
  FormLabelAlign,
  FormLabelAligns
} from './type'
import { validatorSizeValue } from '../../utils'

/**
 * props参数
 */
export const formItemProps = {
  /** label标签文本 */
  label: {
    type: String,
    default: ''
  },
  /** model 的键名, 用于validator时获取校验规则 */
  prop: {
    type: String,
    default: ''
  },
  /** 显示表单域下边框 */
  borderBottom: {
    type: Boolean,
    default: undefined
  },
  /** 标签显示的位置 */
  labelPosition: {
    type: String,
    default: (): FormLabelPosition | '' => {
      return ''
    },
    validator: (value: FormLabelPosition | '') => {
      return value === '' || FormLabelPositions.includes(value)
    }
  },
  /** 标签的宽度, 单位rpx */
  labelWidth: {
    type: [String, Number],
    default: '',
    validator: (value: string | number) => {
      return validatorSizeValue(value)
    }
  },
  /** 标签对齐方式 */
  labelAlign: {
    type: String,
    default: (): FormLabelAlign | '' => {
      return ''
    },
    validator: (value: FormLabelAlign | '') => {
      return value === '' || FormLabelAligns.includes(value)
    }
  },
  /** 标记为必填项 */
  required: {
    type: Boolean,
    default: undefined
  },
  /** 自定义label样式 */
  labelStyle: {
    type: Object,
    default: () => {
      return {}
    }
  }
}
export type FormItemProps = ExtractPropTypes<typeof formItemProps>
